package com.tarena.lbs.message.web.mq;

import com.tarena.lbs.message.web.mq.source.NoticeMessageInputSource;
import com.tarena.lbs.message.web.service.TriggerMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

/**
 * 消息通知MQ消费者
 *
 * @since 2021-06-01
 */
@Component
@Slf4j
@EnableBinding({NoticeMessageInputSource.class})
public class NoticeConsumer {

    @Autowired
    TriggerMessageService triggerMessageService;

    /**
     * 处理接收到的消息
     *
     * @param value 接收到的消息
     * @throws Exception 处理异常
     */
    @StreamListener(NoticeMessageInputSource.IN_PUT)
    public void handle(String value) throws Exception {
        log.info("【消息服务-STREAM-MQ异步消息通知-接收消息】" + value);
        triggerMessageService.handleMessage(value);
    }
}